import {ipcMain} from 'electron'
import {readFile,saveFile} from "../file/demo";

export default function (){
  ipcMain.on('getFile', async (event:Electron.IpcMainEvent  ,path:string) => {
    let resData={
      code:0,
      data:{},
      message:"",
    }
    try{
      let res:any = await readFile(path)
      resData.data = res.toString();
    }catch (e:any) {
      resData.code = 400;
      resData.message = e;
    }finally {
      event.reply('getFileRes',resData)
    }
  });

  ipcMain.on('setFile', async (event:Electron.IpcMainEvent  ,path:string,data:string) => {
    let resData={
      code:0,
      data:{},
      message:"",
    }
    try{
     await saveFile(path,data)
    }catch (e:any) {
      resData.code = 400;
      resData.message = e;
    }finally {
      event.reply('setFileRes',resData)
    }
  })
}

